var _sub_form_id; //formId
var _sub_url;
var _sendGt3_url;



var selectNames;
function closeMsg(){
	$.messager.progress('close');
}
function checkSave(){
	return true;
};

function parentZubmitTab(){
		$.messager.progress({msg:'数据保存中请稍后...'});
		$.ajax({
			type:'post',
			url: _sub_url,
			dataType:'JSON',
			cache: false,
			data:$(_sub_form_id).serialize(),
			success:function(data){
			$.messager.progress('close');
			if (data.code == "0" || data.code == "00" || data.code == "000") {
				successBack();
				$.messager.show({showType:'slide',showSpeed:'600',msg:data.msg+data.reason,title:'提示'});
			} else {
				$.messager.show({showType:'slide',showSpeed:'600',msg:data.msg+data.reason,title:'提示'});
				errorBack();
			}
		},
		error:function(){
			$.messager.progress('close');
			$.messager.alert("错误：","连接服务器超时，请稍候再试！",'error');
		}
		});
}
//保存
function parentBubmitTab(){
	var rest = $(_sub_form_id).form("validate");
	if(rest && checkSave()){
		$.messager.progress({msg:'数据保存中请稍后...'});
		$.ajax({
			type:'post',
			url: _sub_url,
			dataType:'JSON',
			cache: false,
			data:$(_sub_form_id).serialize(),
			success:function(data){
			$.messager.progress('close');
			if (data.code == "0" || data.code == "00" || data.code == "000") {
				successBack();
				//$.messager.alert("提示：",data.msg+data.reason,'success');
				$.messager.show({showType:'slide',showSpeed:'600',msg:data.msg+data.reason,title:'提示'});
			} else {
				//$.messager.alert("提示：",data.msg+data.reason,'error');
				$.messager.show({showType:'slide',showSpeed:'600',msg:data.msg+data.reason,title:'提示'});
				errorBack();
			}
		},
		error:function(){
			$.messager.progress('close');
			$.messager.alert("错误：","连接服务器超时，请稍候再试！",'error');
		}
		});
	}
}

//提交金三
function parentSubmitTab(){
	var rest = $(_sub_form_id).form("validate");
	if(rest && checkSave()){
		$.messager.progress({msg:'数据保存中请稍后...'});
		$.ajax({
			type:'post',
			url: _sub_url,
			dataType:'JSON',
			cache: false,
			data:$(_sub_form_id).serialize(),
			success:function(data){
			if (data.code == "0" || data.code == "00" || data.code == "000") {
				$.ajax({
					type:'post',
					url: _sub_url+"swjg",
					dataType:'JSON',
					cache: false,
					data:$(_swjg_form_id).serialize(),
					success:function(data){
						parent.closeMsg();
						if (data.code == "0" || data.code == "00" || data.code == "000") {
							$.messager.alert("提示：",data.msg+data.reason,'success');
						} else {
							$.messager.alert("提示：",data.msg+data.reason,'error');
						}
						},
						error:function(){
							parent.closeMsg();
							$.messager.alert("错误：","连接服务器超时，请稍候再试！",'error');
						}
				});
			} else {
				$.messager.alert("提示：",data.msg+data.reason,'error');
				errorBack();
			}
		},
		error:function(){
			$.messager.progress('close');
			$.messager.alert("错误：","连接服务器超时，请稍候再试！",'error');
		}
		});
	}
}

function parentSubmitGt3(obj){
	obj.disabled = true;
	$.messager.progress({msg:'数据保存中请稍后...'});
	$.ajax({
		type:'post',
		url: _sendGt3_url,
		dataType:'JSON',
		cache: false,
		data:$(_sub_form_id).serialize(),
		success:function(data){
		$.messager.progress('close');
		if (data.code == "0" || data.code == "00" || data.code == "000") {
			$.messager.alert("提示：",data.msg+data.reason,'success');
			successBackGt3();
		} else {
			$.messager.alert("提示：",data.msg+data.reason,'error');
			obj.disabled = "";
			errorBackGt3();
		}
	},
	error:function(){
		$.messager.progress('close');
		$.messager.alert("错误：","连接服务器超时，请稍候再试！",'error');
	}
	});
}

function successBack(){};
function errorBack(){};
function successBackGt3(){};
function errorBackGt3(){};
/**
 * 数字保留小数位
 * @param obj
 * @param x
 */
function getDecimal(obj,x){
	var value1 = obj.value + "";
	if(value1 != "" && !isNaN(x) && !isNaN(value1)){
		obj.value = parseFloat(value1).toFixed(x);
	}else{
		obj.value = parseFloat("0").toFixed(x);
	}
}

/**
 * 选择动作
 * @param obj
 */
function getChecked(obj){
	var names = obj.id;
	if(names == ""){
		names = obj.name;
	}
	var typeids = document.getElementsByName(names);
	var lv = typeids.length;
	for(var i=0;i<lv;i++){
		typeids[i].checked = false;
	}
	if(lv > 1){
		obj.checked = true;
	}
}

function seletedVal (sel){
	for(var j=0;j<sel.options.length;j++){
		if(sel.options[j].selected){
			return sel.options[j].value;
		}
	}
}

function seleted (sel,inpV){
	for(var j=0;j<sel.options.length;j++){
		if(sel.options[j].value==inpV){
			sel.options[j].selected="selected";
			return;
		}
	}
}

function selectQuery(inpV,url,sel){
	$.ajax({
        type:'POST',
        url:'${url}/cssnj/ajax.action?tld='+url,
        dateType:"json",
        data:{dm:inpV},
        success:function(data){
        	var dataList = JSON.parse(data);
        	sel.options.length = 0;
        	if(dataList.length > 0){
				for(var i=0;i<dataList.length;i++){
					sel.options.add(new Option(dataList[i].dm +' '+ dataList[i].mc,dataList[i].dm));
				}
        	}
        	selBackFun(obj);
        }
    });
}
function selBackFun(obj){};
